package cn.yingxd.demo.javatraining.tester;

import cn.yingxd.demo.javatraining.Main;
import cn.yingxd.demo.javatraining.reflectionapp.Reflector;

public class reflection {
    public static void test(String jarFileName) {
        Reflector.Instance().processClass(Main.class.getName(),
            new Reflector.IAnnotationProcessor() {
                @Override
                public void clazz(String className) {
                    System.out.println("Class: " + className);
                }

                @Override
                public void annotation(String className, String descriptor, boolean visible) {
                    System.out.println("\tAnnotation: " + descriptor + "\n\t\tAnnotationVisible = " + visible);
                }

                @Override
                public void annotationProperty(String className, String descriptor, boolean visible, String propName, Object propValue) {
                    System.out.println("\t\t" + propName + " = " + propValue);
                }
            });
        Reflector.Instance().scanClass(Main.class.getName(),
            new Reflector.IAnnotationProcessor() {
                @Override
                public void clazz(String className) {
                    System.out.println("Class: " + className);
                }

                @Override
                public void annotation(String className, String descriptor, boolean visible) {
                    System.out.println("\tAnnotation: " + descriptor + "\n\t\tAnnotationVisible = " + visible);
                }

                @Override
                public void annotationProperty(String className, String descriptor, boolean visible, String propName, Object propValue) {
                    System.out.println("\t\t" + propName + " = " + propValue);
                }
            });
        if (jarFileName != null && !jarFileName.isEmpty()) {
            Reflector.Instance().scanJar(jarFileName,
                new Reflector.IAnnotationProcessor() {
                    @Override
                    public void clazz(String className) {
                        System.out.println("Class: " + className);
                    }

                    @Override
                    public void annotation(String className, String descriptor, boolean visible) {
                        System.out.println("\tAnnotation: " + descriptor + "\n\t\tAnnotationVisible = " + visible);
                    }

                    @Override
                    public void annotationProperty(String className, String descriptor, boolean visible, String propName, Object propValue) {
                        System.out.println("\t\t" + propName + " = " + propValue);
                    }
                });
        }
    }
}